//
//  Starview.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/6.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "Starview.h"

@implementation Starview {
    NSMutableArray *imgViews;
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
       
        [self creatView];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        
         [self creatView];
    }
    return self;
}

- (void)creatView {
    
    [imgViews removeAllObjects];
    
    if (imgViews == nil) {
        imgViews = [NSMutableArray array];
    }
    
    CGFloat margin = 3;
    CGFloat width = (self.frame.size.width - 18)/5;
    CGFloat height = self.frame.size.height;
    for (int i=0; i<5; i++) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(margin*(i+1)+width*i, 0, width, height)];
        imgView.image = [UIImage imageNamed:@"star_01"];
        imgView.tag = 100+i;
        [imgViews addObject:imgView];
        [self addSubview:imgView];
    }
    
}

- (void)setIndex:(NSInteger)index {
    
    for (UIImageView *imgView in imgViews) {
        
        if (imgView.tag < index+100) {
            imgView.image = [UIImage imageNamed:@"star_02"];
        }
    }
}


@end
